"use strict";
const electron = require("electron");
electron.contextBridge.exposeInMainWorld("electronAPI", {
  on(...args) {
    const [channel, listener] = args;
    return electron.ipcRenderer.on(channel, (event, ...args2) => listener(event, ...args2));
  },
  off(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.off(channel, ...omit);
  },
  send(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.send(channel, ...omit);
  },
  invoke(...args) {
    const [channel, ...omit] = args;
    return electron.ipcRenderer.invoke(channel, ...omit);
  }
  // You can expose other APTs you need here.
  // ...
});
electron.contextBridge.exposeInMainWorld("api", {
  invoke(domain, action, payload) {
    return electron.ipcRenderer.invoke(`rpc:${domain}`, { action, payload });
  }
});
electron.contextBridge.exposeInMainWorld("system", {
  getComputerName: () => electron.ipcRenderer.invoke("system:getComputerName"),
  getPrinters: () => electron.ipcRenderer.invoke("system:getPrinters"),
  getOnlinePrinters: () => electron.ipcRenderer.invoke("system:getOnlinePrinters"),
  printStart: (printerName, data, pageType) => electron.ipcRenderer.invoke("printStart", printerName, data, pageType),
  // WebSocket日志API - 遵循统一门户模式
  writeWsLog: (logLine) => electron.ipcRenderer.invoke("write-ws-log", logLine),
  getWsLogs: (options) => electron.ipcRenderer.invoke("get-ws-logs", options),
  clearWsLogs: () => electron.ipcRenderer.invoke("clear-ws-logs"),
  getWsLogInfo: () => electron.ipcRenderer.invoke("get-ws-log-info")
  // 扫码枪功能使用前端键盘监听，无需主进程 API
});
electron.contextBridge.exposeInMainWorld("net", {
  async isOnline() {
    const res = await electron.ipcRenderer.invoke("rpc:net", { action: "isOnline" });
    return !!(res == null ? void 0 : res.data);
  },
  async probe() {
    const res = await electron.ipcRenderer.invoke("rpc:net", { action: "probe" });
    return !!(res == null ? void 0 : res.data);
  },
  async setOnline(online) {
    const res = await electron.ipcRenderer.invoke("rpc:net", { action: "setOnline", payload: { online } });
    return !!(res == null ? void 0 : res.data);
  }
});
try {
  const sync = (online) => electron.ipcRenderer.invoke("rpc:net", { action: "setOnline", payload: { online } });
  if (typeof navigator !== "undefined") sync(navigator.onLine);
  window.addEventListener("online", () => sync(true));
  window.addEventListener("offline", () => sync(false));
} catch {
}
